package com.design.patterns.structuralModel.iterator.service.file;

import com.design.patterns.structuralModel.iterator.service.ProfileIterator;
import com.design.patterns.structuralModel.iterator.service.bean.Profile;

import java.util.ArrayList;
import java.util.List;

public class QQIterator implements ProfileIterator {
    Integer prosum;
    List<Profile> prifiles;

    public QQIterator(List<Profile> prifiles) {
        this.prosum = 0;
        this.prifiles = prifiles;
    }

    @Override
    public boolean hasNext() {
        int size = prifiles.size();
//        System.out.println("数量" + size);
//        System.out.println("shuduang" + prosum);
        return size-1 >= prosum;
    }

    @Override
    public Profile getNext() {
        if (! hasNext()){
            return null;
        }
        Profile profile = prifiles.get(prosum);
        this.prosum++;
        return profile;
    }

    @Override
    public void reset() {
        prosum = 0;
    }
}
